import Vue from 'vue'
import VueRouter from 'vue-router'
// import HomeView from '../views/HomeView.vue'
// import TestView from '../views/TestView.vue'
import Main from '../views/Main.vue'
import StudentList from '../views/StudentList.vue'
import EmployeeList from '../views/EmployeeList.vue'
import EmployeeAdd from '../views/EmployeeAdd.vue'
import EmployeeModify from '../views/EmployeeModify.vue'
import Login from '../views/Login.vue'
import FindPassword from '../views/FindPassword.vue'
import MenuList from '../views/MenuList.vue'
import RoleList from '../views/RoleList.vue'

Vue.use(VueRouter)

// 在重写push|replace方法时，先把VueRouter原型对象的push|replace保存一份
let originPush = VueRouter.prototype.push
let originReplace = VueRouter.prototype.replace
/**参数1：告诉原来的push | replace方法，你往那里跳转（传递哪些参数）、参数2：成功回调、 参数3：失败回调**/
VueRouter.prototype.push = function (location, resolve, reject) {
    if (resolve && reject) {
        originPush.call(this, location, resolve, reject)
    } else {
        originPush.call(this, location, () => { }, () => { })
    }
}
VueRouter.prototype.replace = function (location, resolve, reject) {
    if (resolve && reject) {
        originReplace.call(this, location, resolve, reject)
    } else {
        originReplace.call(this, location, () => { }, () => { })
    }
}


const routes = [
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/',
    // name: 'main',
    // component: Main
    redirect: '/main'
  },
  {
    path: '/findPassword',
    name: 'findPassword',
    component: FindPassword
  },
  {
    path: '/main',
    // name: 'main',
    component: Main,
    children: [
      {
        path: '/',
        // name: 'studentList',
        // component: StudentList
        redirect: '/studentList'
      },
      {
        path: '/studentList',
        name: 'studentList',
        component: StudentList
      },
      {
        path: '/employeeList',
        name: 'employeeList',
        component: EmployeeList
      },
      {
        path: '/employeeAdd',
        name: 'employeeAdd',
        component: EmployeeAdd
      },
      {
        path: '/employeeModify/:eid',
        name: 'employeeModify',
        component: EmployeeModify
      },
      {
        path: '/menuList',
        name: 'menuList',
        component: MenuList
      },
      {
        path: '/roleList',
        name: 'roleList',
        component: RoleList
      },
    ]
  },
  // {
  //   path: '/',
  //   name: 'home',
  //   component: HomeView
  // },
  // {
  //   path: '/test',
  //   name: 'test',
  //   component: TestView
  // },
  // {
  //   path: '/about',
  //   name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  // }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
